# -*- coding: utf-8 -*-

'''eof
name:学位
code:IG05_EduDegree_2D
tableName:
columnName:
groups:个人通用模块
dependencies:IC_DSJ_2D
type:常用指标
datasourceType:在线指标
description:
eof'''



def PIMFormat():
    # 身份信息
    try:
        data = IC_DSJ_2D.get("data").get("PIM")[0].get("PB01")[0].get("PB01A")
        if data is None:
            return [{}]
        else:
            return data
    except:
        return [{}]

null_type_list = ['', ' ', None, 'null', 'Null', 'NULL', '/', '-', '--']

edu_degree_list = [u'名誉博士', u'博士', u'硕士', u'学士', u'其他']

code_dict = {"1":u'名誉博士', "2":u'博士', "3":u'硕士', "4":u'学士', '0':u'其他', '5':u'其他', '9':u'其他'}


def getIG05():
    try:
        PB01A = PIMFormat()
        if PB01A == [{}]:
            return u'缺失值'
        else:
            PB01AD03 = PB01A[0].get('PB01AD03')
            if PB01AD03 in null_type_list:
                return u'缺失值'
            else:
                edu_degree = code_dict.get(PB01AD03)
                if edu_degree in null_type_list and edu_degree not in edu_degree_list:
                    return u'缺失值'
                else:
                    if edu_degree in [u'学士', u'其他']:
                        return 1
                    elif edu_degree in [u'名誉博士', u'博士', u'硕士']:
                        return 2
    except:
        return u'缺失值'


if __name__ == "__main__":
    import json

    with open('E:/HQDIndicators/IC_DSJ1.json', 'r') as f:
        IC_DSJ_2D = json.loads(f.read())['IC_DSJ']
    print getIG05()

result = getIG05()

